import { defineStore } from "pinia";
import { RouteRecordRaw } from "vue-router";


let modules = import.meta.glob("../views/pages/*.vue")

export const useStore = defineStore('myStore', {
    state: ()=> {
        return {
            routes: [ ] as Array<RouteRecordRaw>
        }
    },
    getters: {},
    actions: {
        // 添加路由
        addRoutes(data: Array<any>, router:any) {
            data.forEach(item=> {
                this.routes.push({
                    path: item.path,
                    name: item.name,
                    component: modules[`../views/pages/${item.component}`],
                })
            })
            this.routes.forEach(m => router.addRoute(m))
        }
    },
    // persist: {
    //     key: 'myStore',
    //     storage: sessionStorage,
    //     // paths: ['routes']
    // }
})